package org.example.day07;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TestMap {
    public static void main(String[] args) {
        Map<Integer,Student> map = new HashMap<>();
        Student s1 = new Student(001,89);
        Student s2 = new Student(002,89);
        Student s3 = new Student(003,89);
        map.put(1,s1);
        map.put(2,s2);
        map.put(3,s3);
        //forEach
        map.forEach((k,v)->{
            System.out.println("key:"+k);
            System.out.println("value:"+v.getId()+"\t"+v.getScore());
        });

//
        Set<Integer> keys = map.keySet();
        for (Integer k : keys){
            System.out.println(k);
            System.out.println(map.get(k).getScore());
        }
        //
        Collection<Student> students = map.values();
        for (Student st : students)
            System.out.println(st.getId()+"\t"+st.getScore());

//
//        System.out.println(map.get(1).getScore());//
//        //验证map集合是否存在某个key
//        System.out.println(map.containsKey(1));//boolean
//        map.remove(1);//删除
//        System.out.println(map.size());//还有多少条数据
//        map.clear();//清空
    }
}
